import {Injectable} from '@nestjs/common';
import {CreateHouseworkDto} from './dto/create-housework.dto';
import {PrismaService} from "../prisma/prisma.service";
import {houseworkEntity} from "./entities/housework.entity";

@Injectable()
export class HouseworkService {
    constructor(private prisma: PrismaService) {
    }

    create(createHouseworkDto: CreateHouseworkDto) {
        return this.prisma.housework.create({
            data: createHouseworkDto,
            include: {
                company: true,
                server: true,
                user: true
            }
        });
    }

    findAllById(id: string): Promise<houseworkEntity[]> {
        return this.prisma.housework.findMany({
            where: {userId: id},
            include: {
                company: true,
                server: true,
                user: true
            }
        });
    }
    findAll(): Promise<houseworkEntity[]> {
        return this.prisma.housework.findMany({
            include: {
                company: true,
                server: true,
                user: true
            }
        });
    }
    findOne(id: string) {
        return this.prisma.housework.findUnique({
            where: {id},
            include: {
                company: true,
                server: true,
                user: true
            }
        })
    }

    update(id: string) {
        return this.prisma.housework.update({
            where: {id},
            data: {isCount:1},
            include: {
                company: true,
                server: true,
                user: true
            }
        });
    }

    remove(id: string) {
        return this.prisma.housework.delete({
            where: {id},
            include: {
                company: true,
                server: true,
                user: true
            }
        });
    }
}
